﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace myfirstmaui.Models
{
    //我直接生产了一个对象，给了.CollectionView.ItemTemplate
    //这里脑袋要转一转.. 反正不难可以很闹心...
    public class LightItemTemplateSelector : DataTemplateSelector
    {
        public DataTemplate DT1 { get; set; }
        public DataTemplate DT2 { get; set; }
        public DataTemplate DT3 { get; set; }
        public DataTemplate DT4 { get; set; }

        public LightItemTemplateSelector()
        {
        }   

        //这里我蒙蔽了，懵逼了，懵逼了... 为什么呀，我在MyPage1里面去定义模板就是跳不尽量，
        //我换了一个方式，NEW一个新的类，就可以跳进来了，搞不懂，搞不懂呀....
        protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
        {
            //ITEM就是每个子项目的东西..
            LightItemModel model = item as LightItemModel;
            if (model != null)
            {
                if (model.ItemType == 1)
                {
                    return DT1;
                }
                if (model.ItemType == 2)
                {
                    return DT2;
                }
                if (model.ItemType == 3)
                {
                    return DT3;
                }
                if (model.ItemType == 4)
                {
                    return DT4;
                }
            }
            return null;
        }

    }
}
